package designpattern.behavioral_patterns;

public class StrategyPattern {

	public class Context {
		Strategy aStrategy;

		public void execute(){
			aStrategy.execute();
		}
		
		public void setaStrategy(Strategy aStrategy) {
			this.aStrategy = aStrategy;
		}
		
	}

	interface Strategy {
		void execute();
	}

	class ConcreteStrategyA implements Strategy {
		@Override
		public void execute() {
			System.out.print("ConcreteStrategyA\n");
		}

	}

	class ConcreteStrategyB implements Strategy  {
		@Override
		public void execute() {
			System.out.print("ConcreteStrategyB\n");
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StrategyPattern pattern = new StrategyPattern();
		//context voi' cac' Strategy khac' nhau
		Context context1 = pattern.new Context();
		context1.setaStrategy(pattern.new ConcreteStrategyA());
		context1.execute();
		//
		context1 = pattern.new Context();
		context1.setaStrategy(pattern.new ConcreteStrategyB());
		context1.execute();
	}

}
